package com.zbkj.crmeb.handler.orderproduct;

import com.zbkj.crmeb.plat.by.dto.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: wsl
 * @date: 2024/2/22 0022 22:21
 * @ClassName: AbstractOrderConfirmHandler
 */
public abstract class AbstractOrderProductHandler implements OrderProductInterface {
    private static final Logger logger = LoggerFactory.getLogger(AbstractOrderProductHandler.class);

    @Override
    public Result execute(OrderProductContext context){
        try {
            boolean check = doPreCheck(context);
            if (!check){
                logger.error("订单确认后置逻辑校验失败");
                return Result.getFailureResult("订单确认后置逻辑校验失败","订单确认后置逻辑校验失败");
            }
            Result result = doHandler(context);
            doAfter(context,result);
            return result;
        }catch (Exception e){
            logger.error("处理订单确认后置逻辑异常:",e);
            return Result.getFailureResult("商品上传失败",e.getMessage());
        }

    }

    @Override
    public boolean doPreCheck(OrderProductContext context) {
        if (null == context){
            return false;
        }
        if (null == context.getStoreOrderInfo()){
            return false;
        }
        if (null == context.getPurchaseGoods()){
            return false;
        }
        return true;
    }


}
